import App from './App'
import {
	createSSRApp
} from 'vue'

let app = createSSRApp(App)

app.config.globalProperties.Vue = Vue
app.config.globalProperties.xaoi = xaoi
import useShare from './utils/useShare.js'
import getDeviceInfoBase from './utils/deviceInfo.js'
getDeviceInfoBase()
Vue.user = function() {
	let user = null;
	return async function(is_new) {
		if (!user || is_new) {
			user = xaoi.ele();

			$post('base/user/info').then(res => {
				user(res)
			})
		}
		return await user();
	}
}()

Vue.$push = (url, bool) => {
	if (bool) {
		var user = uni.getStorageSync('user');
		if (!user) {
			uni.showModal({
				title: '温馨提示',
				content: '请先登录~',
				confirmText: '去登录',
				cancelText: '继续浏览',
				confirmColor: '#0f956e',
				complete(e) {
					if (e.confirm) {
						uni.navigateTo({
							url: "/pages/login/login"
						});
					}
				}
			})
			return;
		}
	};

	switch (url) {
		case "/pages/index/index":
		case "/pages/zhibo/index":
		case "/pages/user/index":
			uni.switchTab({
				url
			});
			break;
		default:
			uni.navigateTo({
				url
			});
			break;
	}
}
app.config.globalProperties.$push = Vue.$push

//#ifdef H5
window.xaoi = xaoi;
window.Vue = Vue;
window.$push = Vue.$push;
//#endif

import uviewPlus from '@/uni_modules/uview-plus'
app.use(uviewPlus)

import xi_ad from './components/xi/ad.vue'
app.component('xi-ad', xi_ad)

import xi_list from './components/xi/list.vue'
app.component('xi-list', xi_list)

import xi_list_tabs from './components/xi/list-tabs.vue'
app.component('xi-list-tabs', xi_list_tabs)

import xi_select from './components/xi/select.vue'
app.component('xi-select', xi_select)

import xi_img from './components/xi/img.vue'
app.component('xi-img', xi_img)

import xi_pbl from './components/xi/pbl.vue'
app.component('xi-pbl', xi_pbl)

import ssq_picker from './components/xi/ssq-picker.vue'
app.component('ssq-picker', ssq_picker)

import xi_login from './components/xi/login.vue'
app.component('xi-login', xi_login)

import xi_image from './components/xi/image.vue'
app.component('xi-image', xi_image)

import xi_files from './components/xi/files.vue'
app.component('xi-files', xi_files)

import uploadImage from './components/uploadImage.vue'
app.component('upload-image', uploadImage)
// let mixin= require('@/utils/mixin.js'); 

// import 
export function createApp() {
	app.mixin(useShare())
	return {
		app
	}
}